package com.spring.future.modules.sys.web;

import com.spring.future.common.domain.SearchEntity;
import com.spring.future.common.mybatis.domain.Page;
import com.spring.future.common.utils.ObjectMapperUtils;
import com.spring.future.common.utils.RequestUtils;
import com.spring.future.modules.sys.domain.New;
import com.spring.future.modules.sys.domain.Product;
import com.spring.future.modules.sys.service.NewService;
import com.spring.future.modules.sys.service.ProductService;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by zh on 2017/1/15.
 */
@RestController
public class ProductController {
    @Autowired
    private ProductService productService;

    @RequestMapping(value = "/weixin/getProductList")
    public String getNews(HttpServletRequest request){
        SearchEntity searchEntity = RequestUtils.getSearchEntity(request, New.class.getName());
        Page<Product> page = productService.findPage(searchEntity.getPageable(), searchEntity.getParams());
        return ObjectMapperUtils.writeValueAsString(page);
    }

    @RequestMapping(value = "/weixin/getProductDetail")
    public String getProductDetail(String id){
        Product product = productService.findOne(id);
        return ObjectMapperUtils.writeValueAsString(product);
    }

}
